/*
 * Copyright 2009 Vladimir Ritz Bossicard
 *
 * This file is part of OraDoc.
 *
 * OraDoc is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * Version     : $Revision: 20 $
 * Last edit   : $Date: 2009-03-25 12:43:30 +0000 (Wed, 25 Mar 2009) $
 * Last editor : $Author: vbossica $
 */
package org.oradoc.projects;

import java.util.ArrayList;
import java.util.List;

import org.oradoc.ProcessListener;
import org.oradoc.structures.dao.TableDao;
import org.oradoc.structures.dao.TableTO;
import org.oradoc.structures.dao.ViewDao;
import org.oradoc.structures.dao.ViewTO;

/**
 *
 * @author Vladimir Ritz Bossicard
 */
public class Project {

    private String name;
    private String version;

    private TableDao tableDao;
    private ViewDao viewDao;

    private List<TableTO> tables = new ArrayList<TableTO>();
    private List<ViewTO> views = new ArrayList<ViewTO>();

    public Project(final String name, final String version) {
        this.name = name;
        this.version = version;
    }

    public String getName() {
        return this.name;
    }

    public String getVersion() {
        return this.version;
    }

    public void setTableDao(final TableDao tableDao) {
        this.tableDao = tableDao;
    }

    public void setViewDao(final ViewDao viewDao) {
        this.viewDao = viewDao;
    }

    public List<TableTO> getAllTables() {
        return this.tables;
    }

    public List<ViewTO> getAllViews() {
        return this.views;
    }

    public void process(final ProcessListener listener) {
        listener.info("loading tables");
        List<String> tableNames = this.tableDao.getAllTableNames();
        listener.info("loading views");
        List<String> viewNames = this.viewDao.getAllViewNames();

        int total = tableNames.size() + viewNames.size();
        int current = 0;
        for (String name : tableNames) {
            listener.step(++current, total, "loading table '" + name + "'");
            this.tables.add(this.tableDao.loadTable(name));
        }

        for (String name : viewNames) {
            listener.step(++current, total, "loading view '" + name + "'");
            this.views.add(this.viewDao.loadView(name));
        }
    }

}
